package com.leyou.statis.listener;

import com.leyou.statis.service.StatisService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zqq
 * @ClassName StatisListener
 * @Description
 * @date 2020/4/8-11:56
 */
@Component
public class StatisListener {

    @Autowired
    private StatisService statisService;

    /**
     * 处理订单付款后，统计表添加数据的消息
     *
     * @param id
     * @throws Exception
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "leyou.create.statis.queue", durable = "true"),
            exchange = @Exchange(
                    value = "leyou.statis.exchange",
                    ignoreDeclarationExceptions = "true",
                    type = ExchangeTypes.TOPIC),
            key = {"statis.insert"}))
    public void listenCreate(Long id) throws Exception {
        if (id == null) {
            return;
        }
        statisService.addStatis(id);
    }
}
